package ysq.xyg.recovery.controller;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.recovery.model.po.RecoverySmallCat;
import ysq.xyg.recovery.model.vo.RecoverySmallCatVo;
import ysq.xyg.recovery.service.RecoverySmallCatService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 回收金模块-小分类controller层
 *
 * @author congcong tao
 * @date 2019-5-8 15:12:31
 */
@RestController
public class RecoverySmallCatController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(RecoverySmallCatController.class);
    @Resource
    private RecoverySmallCatService recoverySmallCatService;

    private RecoverySmallCat recoverySmallCat;

    /**
     * 分页查询
     *
     * @param recoverySmallCatVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-5-8 15:12:31
     */
    @BaseLog(module = "回收金模块",className = "小分类",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoverySmallCat/page",method = RequestMethod.POST)
    public ReturnEntity page(RecoverySmallCatVo recoverySmallCatVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = recoverySmallCatService.page(recoverySmallCatVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-5-8 15:12:31
     */
    @RequestMapping(value = "/recoverySmallCat/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/recovery/recoverySmallCatUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            recoverySmallCat = recoverySmallCatService.selectByPrimaryKey(id);
            view.addObject("recoverySmallCat", recoverySmallCat);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-5-8 15:12:31
     */
    @BaseLog(module = "回收金模块",className = "小分类",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoverySmallCat/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return recoverySmallCatService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param recoverySmallCatVo Vo对象
     * @author congcong tao
     * @date 2019-5-8 15:12:31
     */
    @BaseLog(module = "回收金模块",className = "小分类",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoverySmallCat/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,RecoverySmallCatVo recoverySmallCatVo){
        return recoverySmallCatService.addOrUpdate(recoverySmallCatVo,acceptCurrentUser(request));
    }

    /**
     * 根据code查询select列表
     * @param code
     * @author congcong tao
     * @date 2019/7/8 16:55
     */
    @RequestMapping(value = "/recoverySmallCat/acceptSelect",method = RequestMethod.POST)
    public ReturnEntity acceptSelect(String code){
        return recoverySmallCatService.acceptSelect(code);
    }

    /**
     * 根据id查询json数据
     * @param id
     * @author congcong tao
     * @date 2019/7/8 16:56
     */
    @RequestMapping(value = "/recoverySmallCat/getRecoverySmallCatById",method = RequestMethod.POST)
    public ReturnEntity getRecoverySmallCatById(String id){
        recoverySmallCat = recoverySmallCatService.selectByPrimaryKey(id);
        return new ReturnEntity(recoverySmallCat);
    }
}